<?php

class ForageGeoQueryBehaviour extends ForageQueryBehaviour
{
  private $latitude;
  private $longitude;
  private $radius;

  public function __get($name)
  {
    switch ($name) {
    case 'latitude':
    case 'longitude':
    case 'radius':
      return $this->$name;
    }
  }

  public function setPoint($latitude, $longitude)
  {
    if (!is_numeric($latitude) || !is_numeric($longitude)) {
      throw new InvalidArgumentException('Expecting numeric values for longitude and latitude');
    }
    if ($latitude > 90 || $latitude < -90) {
      throw new InvalidArgumentException('Invalid latitude [' . $latitude . '] must be between -90 and 90');
    }
    if ($longitude > 180 || $longitude < -180) {
      throw new InvalidArgumentException('Invalid longitude [' . $longitude . '] must be between -180 and 180');
    }
    $this->latitude  = $latitude;
    $this->longitude = $longitude;
  }

  public function setRadius($radius)
  {
    if (!is_numeric($radius)) {
      throw new InvalidArgumentException('Expecting a numeric value for radius [' . $radius . ']');
    }
    $this->radius = $radius;
  }
}
